<template>
  <div
    class="dialog"
    :class="{ show: modelData?.show }"
    @touchmove.stop.prevent="stop($event, '')"
  >
    <div class="mask">
      <div class="content">
        <!-- 头部 -->
        <div class="header" v-if="modelData?.header !== false">
          {{ modelData?.title || "提示" }}
        </div>
        <!-- 中间内容 -->
        <scroll-view scroll-y="true" class="center-box">
          <!-- 自定义内容 -->
          <slot name="content"></slot>
          <!-- 提示文案 -->
          <div
            class="tips-text"
            :style="modelData?.style"
            v-if="modelData?.text"
          >
            {{ modelData?.text }}
          </div>
        </scroll-view>
        <!-- 底部 -->
        <div class="footer-formData" v-if="modelData?.footer !== false">
          <button
            class="btn-formData"
            v-if="modelData?.cancelBtn !== false"
            @click="cancel"
          >
            {{ modelData?.cancelText || "取消" }}
          </button>
          <button class="btn-formData" @click="confirm">
            {{ modelData?.okText || "确认" }}
          </button>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref } from "vue";
// import debounce from "@/utils/debounce";
export default defineComponent({
  props: {
    /**
     * 默认值
     * show: false // 展示
     * header: true
     * title: "提示"
     * footer：true
     * cancelText: "取消"
     * okText: "确认"
     * text： "文案内容"
     */
    model: Object,
  },
  setup(props) {
    let modelData = ref(props.model);

    return {
      modelData,
    };
  },
  methods: {
    stop(e: { stopPropagation: () => any }, tap: any) {
      tap && e.stopPropagation();
    },
    // 确定
    confirm() {
      this.$emit("confirmChange");
    },
    // 取消
    cancel() {
      this.modelData.show = false;
      this.$emit("cancelChange");
    },
  },
});
</script>
<style lang="scss" scoped>
.dialog {
  height: 100vh;
  width: 100vw;
  background: #0000003c;
  position: fixed;
  display: flex;
  align-items: center;
  left: 0;
  top: 0;
  z-index: 1002;
  transition: all ease-in-out 0.2s;
  visibility: hidden;
  opacity: 0;

  .mask {
    width: 100%;
    margin-bottom: 180rpx;
    .content {
      background-color: #fff;
      margin: 0 auto;
      border-radius: 16rpx;
      overflow: hidden;
      width: 620rpx;
      position: relative;
    }

    .header {
      font-weight: 700;
      width: 100%;
      text-align: center;
      padding: 34rpx 0;
      font-size: 32rpx;
      border-bottom: 1px solid #f0f0f0;
    }

    .center-box {
      max-height: 550rpx;
      overflow-y: auto;
    }

    .form-item {
      display: flex;
      justify-content: space-between;
      margin: 24rpx 30rpx;
      align-items: center;

      .suffix {
        white-space: nowrap;
        margin-left: 16rpx;
      }

      .border {
        border: 1px solid #f0f0f0;
        padding: 0 16rpx;
        flex: 1;
        min-width: 0;
        border-radius: 16rpx;
        display: flex;
        justify-content: space-between;
        height: 72rpx;
        line-height: 72rpx;
        align-items: center;
        position: relative;

        .text {
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
          width: 100%;
        }

        .num {
          text-align: right;
          font-size: 24rpx;
          color: #999;
          right: 20rpx;
          position: absolute;
          top: 0;
        }
      }

      .label {
        max-width: 255rpx;
        min-width: 160rpx;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;

        .text {
          color: red !important;
        }
      }

      .inp {
        width: 100%;
      }

      .val {
        display: flex;
        align-content: center;

        .iconfont {
          margin-left: 16rpx;
          color: #d8d8d8;
          margin-top: 4rpx;
        }

        .picker-inp {
          min-width: 360rpx;
        }
      }

      &.textarea {
        align-items: initial;
        border-bottom: 0;
        display: inherit;

        .textarea-item {
          width: 100%;
          position: relative;
          margin-top: 16rpx;

          .textarea-inp {
            width: calc(100% - 40rpx);
            border: 1px solid #f0f0f0;
            padding: 20rpx 20rpx 50rpx;
            border-radius: 10rpx;
            min-height: 110rpx !important;
            position: relative;
          }

          .num {
            text-align: right;
            font-size: 24rpx;
            color: #999;
            right: 20rpx;
            position: absolute;
            bottom: 20rpx;
          }
        }
      }
    }

    .footer-formData {
      display: flex;
      justify-content: center;
      width: calc(100% - 30rpx);
      padding-top: 20rpx;
      margin: 0 15rpx;

      .btn-formData {
        text-align: center;
        height: 80rpx;
        line-height: 80rpx;
        font-size: 28rpx;
        border-radius: 0;
        width: 264rpx;
        color: #999;
        border-radius: 8rpx;
        margin: 0 0 24rpx;

        & + .btn-formData {
          margin-left: 30rpx;
        }

        &::after {
          border: 1px solid #e8e8e8;
        }

        &:first-of-type {
          background-color: #fff;
        }

        &:last-of-type {
          background-color: #0abbb9;
          color: #fff;
          border-color: #0abbb9;
        }
      }
    }

    .tips-text {
      padding: 40rpx;
      text-align: center;
    }
  }
}

.show {
  visibility: visible;
  opacity: 1;
}
</style>
